home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Utils / Software2 / Product11 / Setup.exe / MT-3.16-full-en_US / mt-load.cgi < prev    next >
Text File  |  2005-04-18  |  9KB  |  338 lines

  1. #!/usr/bin/perl -w
  2.  
  3. # Copyright 2001-2005 Six Apart. This code cannot be redistributed without
  4. # permission from www.movabletype.org.
  5. #
  6. # $Id: mt-load.cgi.pre 10670 2005-03-24 01:32:02Z ezra $
  7. use strict;
  8.  
  9. my($MT_DIR);
  10. BEGIN {
  11.     if ($0 =~ m!(.*[/\\])!) {
  12.         $MT_DIR = $1;
  13.     } else {
  14.         $MT_DIR = './';
  15.     }
  16.     unshift @INC, $MT_DIR . 'lib';
  17.     unshift @INC, $MT_DIR . 'extlib';
  18. }
  19.  
  20. local $| = 1;
  21.  
  22. use MT::L10N;
  23. my $LH = MT::L10N->get_handle('en_US');
  24.  
  25.     sub trans_templ {
  26.         my($text) = @_;
  27.         $text =~ s!<MT_TRANS((\s\w+=(["'])[^"]*\3)+)>!
  28.             my($msg, %args) = ($1);
  29.             #print $msg;
  30.             while ($msg =~ /(\w+)\s*=\s*(["'])(.*?)\2/g) {  #"
  31.                 $args{$1} = $3;
  32.             }
  33.             $args{params} = '' unless defined $args{params};
  34.             my @p = map MT::Util::decode_html($_),
  35.                     split /\s*%%\s*/, $args{params};
  36.             @p = ('') unless @p;
  37.             $LH->maketext($args{phrase}, @p);
  38.         !ge;
  39.         $text;
  40.     }
  41.  
  42. print "Content-Type: text/html; charset=utf-8\n\n";
  43. print trans_templ(<<HTML) unless (grep {$_ eq '--nostyle' } @ARGV);
  44.  
  45. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  46. <html xmlns="http://www.w3.org/1999/xhtml">
  47.  
  48. <head>
  49.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  50.     <meta http-equiv="content-language" content="en" />
  51.     
  52.     <title>Movable Type System Loader [mt-load.cgi]</title>
  53.     
  54.     <style type=\"text/css\">
  55.         <!--
  56.         
  57.             body {
  58.                 font-family : Trebuchet MS, Tahoma, Verdana, Arial, Helvetica, Sans Serif;
  59.                 font-size : smaller;
  60.                 padding-top : 0px;
  61.                 padding-left : 0px;
  62.                 margin : 0px;
  63.                 padding-bottom : 40px;
  64.                 width : 80%;
  65.                 border-right : 1px dotted #8faebe;
  66.             }
  67.             
  68.             h1 {
  69.                 background : #8faebe;
  70.                 font-size: large;
  71.                 color : white;
  72.                 padding : 10px;
  73.                 margin-top : 0px;
  74.                 margin-bottom : 20px;
  75.                 text-align : center;
  76.             }
  77.             
  78.             h2 {
  79.                 color: #fff;
  80.                 font-size: small;
  81.                 background : #8faebe;
  82.                 padding : 5px 10px 5px 10px;
  83.                 margin-top : 30px;
  84.                 margin-left : 40px;
  85.                 margin-right : 40px;
  86.             }
  87.             
  88.             h3 {
  89.                 color: #333;
  90.                 font-size: small;
  91.                 margin-left : 40px;
  92.                 margin-bottom : 0px;
  93.                 padding-left : 20px;
  94.             }
  95.     
  96.             p {
  97.                 padding-left : 20px;
  98.                 margin-left : 40px;
  99.                 margin-right : 60px;
  100.                 color : #666;
  101.             }
  102.             
  103.             ul {
  104.                 padding-left : 40px;
  105.                 margin-left : 40px;
  106.             }
  107.             
  108.             code {
  109.                 font-size : small;
  110.             }
  111.             .info {
  112.                 margin-left : 60px;
  113.                 margin-right : 60px;
  114.                 padding : 20px;
  115.                 border : 1px solid #666;
  116.                 background : #eaf2ff;
  117.                 color : black;
  118.             }
  119.         
  120.             .alert {
  121.                 margin-left : 60px;
  122.                 margin-right : 60px;
  123.                 padding : 20px;
  124.                 border : 1px solid #666;
  125.                 background : #ff9;
  126.                 color : black;
  127.             }
  128.             
  129.  
  130.             .ready {
  131.                 color: #fff;
  132.                 background-color: #9C6;
  133.             }
  134.  
  135.             .bad {
  136.                 padding-top : 0px;
  137.                 margin-top : 4px;
  138.                 border-left : 1px solid red;
  139.                 padding-left : 10px;
  140.                 margin-left : 60px;
  141.             }
  142.             
  143.             .good {
  144.                 color: #93b06b;
  145.                 padding-top : 0px;
  146.                 margin-top : 0px;
  147.             }
  148.         
  149.         //-->
  150.     </style>
  151.  
  152. </head>
  153.  
  154. <body>
  155.  
  156. <h1><MT_TRANS phrase="Movable Type System Loader"> [mt-load.cgi]</h1>
  157.  
  158. <p class="info"><MT_TRANS phrase="This page configures Movable Type to run on your system. If all of the tasks needed to set up Movable Type complete succesfully on your server, you will see a notice to that effect at the bottom of this page. If there are any problems during setup, you will see them display on this page so that you can make the appropriate corrections."></p>
  159.  
  160. <h2><MT_TRANS phrase="Movable Type System Setup"></h2>
  161.  
  162. HTML
  163.  
  164.  
  165. use File::Spec;
  166.  
  167. eval {
  168.  
  169. my $tmpl_list;
  170. eval { $tmpl_list = require 'MT/default-templates.pl' };
  171. die "Can't find default template list; where is 'default-templates.pl'?\n" .
  172.     "Error: $@\n"
  173.     if $@ || !$tmpl_list || ref($tmpl_list) ne 'ARRAY' || !@$tmpl_list;
  174.  
  175. print trans_templ("<h3><MT_TRANS phrase='Loading initial data into system...'></h3>\n");
  176.  
  177. require MT;
  178. my $mt = MT->new( Config => $MT_DIR . 'mt.cfg', Directory => $MT_DIR )
  179.     or die MT->errstr;
  180.  
  181. if ($mt->{cfg}->ObjectDriver =~ /^DBI::(.*)$/) {
  182.     my $type = $1;
  183.     my $dbh = MT::Object->driver->{dbh};
  184.     my $schema = File::Spec->catfile($MT_DIR, 'schemas', $type . '.dump');
  185.     open FH, $schema or die "<p class=\"bad\">Can't open schema file '$schema': $!</p>";
  186.     my $ddl;
  187.     { local $/; $ddl = <FH> }
  188.     close FH;
  189.     my @stmts = split /;/, $ddl;
  190.     print trans_templ("<h3><MT_TRANS phrase='Loading database schema...'></h3>\n\n");
  191.     for my $stmt (@stmts) {
  192.         $stmt =~ s!^\s*!!;
  193.         $stmt =~ s!\s*$!!;
  194.         next unless $stmt =~ /\S/;
  195.         $dbh->do($stmt) or die $dbh->errstr;
  196.     }
  197. }
  198.  
  199. use MT::Author qw(AUTHOR COMMENTER);
  200. require MT::Blog;
  201.  
  202. ## First check if there are any authors or blogs currently--if there
  203. ## are, don't run the rest of the script, because we don't want to add
  204. ## the default author back in (hack).
  205. if (MT::Author->count || MT::Blog->count) {
  206.     print trans_templ(<<MSG), security_notice();
  207.  
  208. <h2><MT_TRANS phrase="System Already Initialized"></h2>
  209.  
  210. <p class="bad"><MT_TRANS phrase="It looks like your database has already been initialized by mt-load.cgi. Re-running this script will create a security hole, so this script has been prevented from running."></p>
  211.  
  212. MSG
  213.     exit;
  214. }
  215.  
  216. print trans_templ("<h3><MT_TRANS phrase='Loading weblog'>...</h3>\n");
  217. my $blog = MT::Blog->new;
  218. $blog->name($LH->maketext('First Weblog'));
  219. $blog->archive_type('Individual,Monthly,Category');
  220. $blog->archive_type_preferred('Individual');
  221. $blog->days_on_index(7);
  222. $blog->words_in_excerpt(40);
  223. $blog->file_extension('html');
  224. $blog->convert_paras(1);
  225. $blog->convert_paras_comments(1);
  226. $blog->sanitize_spec(0);
  227. $blog->allow_reg_comments(0);
  228. $blog->allow_unreg_comments(1);
  229. $blog->moderate_unreg_comments(1);
  230. $blog->allow_comments_default(1);
  231. $blog->allow_pings_default(0);
  232. $blog->ping_weblogs(0);
  233. $blog->ping_blogs(0);
  234. $blog->ping_technorati(0);
  235. $blog->server_offset(0);
  236. $blog->language('en_US');
  237. $blog->sort_order_posts('descend');
  238. $blog->sort_order_comments('ascend');
  239. $blog->status_default(1);
  240. $blog->custom_dynamic_templates('none');
  241. $blog->children_modified_on('20040101000000');
  242. $blog->save or die $blog->errstr;
  243.  
  244. print trans_templ("<h3><MT_TRANS phrase='Loading author...'></h3>");
  245. my $author = MT::Author->new;
  246. $author->name('Melody');
  247. $author->type(AUTHOR);
  248. $author->set_password('Nelson');
  249. $author->email('');
  250. $author->can_create_blog(1);
  251. $author->can_view_log(1);
  252. $author->preferred_language('en_US');
  253. $author->save or die $author->errstr;
  254.  
  255. print "<h3><MT_TRANS phrase='Loading permissions...'></h3>\n";
  256. require MT::Permission;
  257. my $perms = MT::Permission->new;
  258. $perms->author_id($author->id);
  259. $perms->blog_id($blog->id);
  260. $perms->set_full_permissions;
  261. $perms->save or die $perms->errstr;
  262.  
  263. print trans_templ("<h3><MT_TRANS phrase='Loading templates'>...</h3>\n");
  264. require MT::Template;
  265.  
  266. my @arch_tmpl;
  267. for my $val (@$tmpl_list) {
  268.         $val->{name} = $mt->translate($val->{name});
  269.     $val->{text} = $mt->translate_templatized($val->{text});
  270.     my $obj = MT::Template->new;
  271.     $obj->build_dynamic(0);
  272.     $obj->set_values($val);
  273.     $obj->blog_id($blog->id);
  274.     $obj->save or die $obj->errstr;
  275.     if ($val->{type} eq 'archive' || $val->{type} eq 'individual' ||
  276.         $val->{type} eq 'category') {
  277.         push @arch_tmpl, $obj;
  278.     }
  279. }
  280.  
  281. print trans_templ("<h3><MT_TRANS phrase='Mapping templates to blog archive types...'></h3>\n");
  282. require MT::TemplateMap;
  283.  
  284. for my $tmpl (@arch_tmpl) {
  285.     my(@at);
  286.     if ($tmpl->type eq 'archive') {
  287.         @at = qw( Daily Weekly Monthly );
  288.     } elsif ($tmpl->type eq 'category') {
  289.         @at = qw( Category );
  290.     } elsif ($tmpl->type eq 'individual') {
  291.         @at = qw( Individual );
  292.     }
  293.     for my $at (@at) {
  294. #        print trans_templ('<p class="good"><MT_TRANS phrase="Mapping template ID [_1] to \'[_2]\'" params="' . $tmpl->id . '%%' . $at . '"></p>' . "\n");
  295.         my $map = MT::TemplateMap->new;
  296.         $map->archive_type($at);
  297.         $map->is_preferred(1);
  298.         $map->template_id($tmpl->id);
  299.         $map->blog_id($tmpl->blog_id);
  300.         $map->save
  301.             or die "Save failed: ", $map->errstr;
  302.     }
  303. }
  304.  
  305. };
  306. if ($@) {
  307.     print <<HTML;
  308.  
  309. <p class="bad">An error occurred while loading data:</p>
  310.  
  311. <p class="alert">$@</p>
  312.  
  313. HTML
  314. } else {
  315.     print trans_templ(<<HTML), security_notice();
  316.  
  317.     <h2 class="ready"><MT_TRANS phrase="System Initialization Complete"></h2>
  318.  
  319.     <p><MT_TRANS phrase="Done loading initial data! All went well. You can now continue with setup of the Movable Type system as described in the installation instructions."></p>
  320.  
  321. HTML
  322. }
  323.  
  324.  
  325. sub security_notice {
  326.     return trans_templ(<<TEXT);
  327.     
  328. <h2><MT_TRANS phrase="Very Important:"></h2>
  329.  
  330. <p class="info"><MT_TRANS phrase="Now that you have run mt-load.cgi, you will never need to run it again. You should now "><strong><MT_TRANS phrase="delete [_1]" params="<code>mt-load.cgi</code>"></strong><MT_TRANS phrase=" from your webserver."></p>
  331.  
  332. <p class="alert"><strong><MT_TRANS phrase="Failure to delete [_1] introduces a MAJOR SECURITY RISK." params="<code>mt-load.cgi</code>"></strong></p>.
  333. TEXT
  334. }
  335.  
  336.  
  337. print "</body>\n\n</html>\n";
  338.